package com.niiuzu.client.screen.feed;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
import com.niiuzu.client.i18n.CommonMessages;
import com.niiuzu.client.util.Constants;

/**
 * Implémentation de la vue pour la gestion des flux et des données RSS.
 */
public class FeedViewImpl extends Composite implements FeedView {

	/**
	 * Interface {@link UiBinder} adaptée à la vue {@link FeedViewImpl}.
	 */
	interface SuitedUiBinder extends UiBinder<Widget, FeedViewImpl> {

	}

	@UiField
	Label applicationVersionLabel;
	@UiField
	Panel channelFilterContainer;
	@UiField
	Panel feedViewerContainer;
	@UiField
	Button refreshButton;
	@UiField
	Widget refreshMessage;

	@Override
	public void createView() {
		SuitedUiBinder uiBinder = GWT.create(SuitedUiBinder.class);
		initWidget(uiBinder.createAndBindUi(this));

		CommonMessages commonMessages = GWT.create(CommonMessages.class);

		String versionValue = Constants.APPLICATION_VERSION;
		String versionText = commonMessages.applicationVersion(versionValue);
		applicationVersionLabel.setText(versionText);
	}

	@Override
	public String toString() {
		return this.getClass().toString();
	}

	@Override
	public void disableActionComponents() {
		refreshButton.setEnabled(false);
	}

	@Override
	public void enableActionComponents() {
		refreshButton.setEnabled(true);
	}

	@Override
	public HasClickHandlers getRefreshHasClickHandlers() {
		return refreshButton;
	}

	@Override
	public void hideRefreshMessage() {
		refreshMessage.setVisible(false);
	}

	@Override
	public void showRefreshMessage() {
		refreshMessage.setVisible(true);
	}

	@Override
	public void setChannelFilterView(IsWidget channelFilterView) {
		channelFilterContainer.add(channelFilterView);
	}

	@Override
	public void setFeedViewerView(IsWidget feedViewerView) {
		feedViewerContainer.add(feedViewerView);
	}

}
